package org.djw.quartz.jobs;

import org.djw.basic.constant.BaseConstants;
import org.djw.order.service.IAdoptOrderService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class MainJob implements Job {
    /**
     * MainJob是在QuartzUtils中,通过newJob(cls) 动态创建并添加到容器中的
     *  所以这里能直接注入容器中的对象
     */
    @Autowired
    private IAdoptOrderService adoptOrderService;
    
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Map<String,Object> map = (Map<String, Object>) jobDataMap.get("params");
        String type = (String) map.get("type");
        Long orderId =Long.valueOf(map.get("orderId").toString());
        switch (type) {
            case BaseConstants.PAY_TIMEOUT_CANCEL_ADOPT:{
                //调用领养订单业务取消订单就可以了
                adoptOrderService.cancelOrderByQuartz(orderId);
                break;
            }
            case BaseConstants.PAY_TIMEOUT_CANCEL_PRODUCT:{
                //调用服务订单业务取消订单就可以了

                break;
            }

            default:break;
        }

    }
}